package com.settlement.system.controller;

import com.settlement.system.common.constant.StandardConstant;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.common.util.RequestContextUtils;
import com.settlement.system.common.util.SecurityUtils;
import com.settlement.system.mapper.security.userdetails.SysUserDetails;
import com.settlement.system.model.entity.common.SystemUser;
import com.settlement.system.model.entity.common.TblRefundAuditBillExport;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.ITblRefundAuditBillExportService;
import com.settlement.system.common.util.common.FasUtil;
import com.settlement.system.common.util.common.SystemUserUtil;
import io.swagger.annotations.Api;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 退款稽核单据主表 前端控制器
 * @author xiaochuan
 * @since 2020-07-23
 */

@Api(tags = "退款稽核单据主表",description = "退款稽核单据主表")
@RestController
@RequestMapping("/refund/audit/bill/dtls")
public class TblRefundAuditBillExportController extends ExcelController<TblRefundAuditBillExport> {

    @Resource
    private ITblRefundAuditBillExportService tblRefundAuditBillExportService;

    @Override
    public IBaseService init() {
        return tblRefundAuditBillExportService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblRefundAuditBillExport.class;
    }


    @Override
    protected List<TblRefundAuditBillExport> getExportDate(Map<String, Object> params) throws ServiceException {
        List<TblRefundAuditBillExport> tempList = new ArrayList<>();
        tblRefundAuditBillExportService.getDataBillByHandler(params, new ResultHandler<TblRefundAuditBillExport>() {

            @Override
            public void handleResult(ResultContext<? extends TblRefundAuditBillExport> resultContext) {
                tempList.add(resultContext.getResultObject());
            }
        });
        return tempList;
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        SysUserDetails user = SecurityUtils.getUser();;
        model.put("authorityNo","auth_001");
        model.put("loginName",user.getUsername());
        model.put("orderSourcePermissionList", RequestContextUtils.getHttpSession().getAttribute(StandardConstant.USER_ORDER_SOURCE_PERMISSION));
        FasUtil.formatInQueryCondition(model,"refBillNo","threeLevelChannelNo","orderSourceNo","billStatusNo");
    }

}

